﻿/*
* 转介盘
*/
var simpleTreeCollection;
$(document).ready(function() {    

    // 自动加载用户
    $("#usubclass").autocomplete("../../Ajax/GetUserAuto.aspx", {
        minChars: 0,
        extraParams: {
            exists: '1',
            uname: function() {
                return escape($('#usubclass').val());
            },
            tname: function() {
                return escape($('#umainclass').val());
            }
        },
        scrollHeight: 300,
        width: 230,
        max: 100
    });

});


//选中部门|用户
function selDU() {
    document.getElementById("utxtmain").value = $("#umainclass").val();
    document.getElementById("utxtsub").value = $("#usubclass").val();
}

//选择了部门
$("#umainclass").result(function(event, data, formatted) {
    flushUser();
});

//刷新用户
function flushUser() {
    $("#usubclass").flushCache();
}

//显示部门树
function showDept(obj) {
    obj = document.getElementById(obj)
    if (obj.style.display == 'block') {
        obj.style.display = 'none';
        $("#selDept").html('↓');
    } else {
        obj.style.display = 'block';
        $("#selDept").html('↑');
    }
    //定位
    var p = $("#selDept");
    var position = p.position();
    obj.style.left = position.left;
    obj.style.top = position.top + 18;
}

//选择部门
function jt(did, dname) {
    $("#umainclass").val(dname);
    document.getElementById('utxtmain').value = dname;
    showDept('dvDept');

    flushUser();
}

// 加载部门树
simpleTreeCollection = $('.simpleTree').simpleTree({
    autoclose: false,
    drag: false,
    afterClick: function(node) {
        //alert('text-'+$('span:first',node).text());
    },
    afterDblClick: function(node) {
        //alert('text-'+$('span:first',node).text());
    },
    afterMove: function(destination, source, pos) {
        //alert('destination-'+destination.attr('id')+' source-'+source.attr('id')+' pos-'+pos);
    },
    afterAjax: function() {
        //alert('Loaded');
    },
    animate: false
    //,docToFolderConvert:true
});